package com.hcom.transaction.controller;

import cn.hutool.extra.qrcode.QrCodeException;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description： https://blog.csdn.net/weixin_50394734/article/details/117913438?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-3-117913438-blog-115689786.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-3-117913438-blog-115689786.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=4
// * 可用img标签进行接收 -->
 * <img th:src="xxxurl地址/getQRCode">
 * @Author：曹杰克
 * @CreateTime：2022/10/27 16:06
 */
@Controller
public class getQRCode {
    /**
     * 获取二维码
     * yuanzidu
     * @return  ,String info
     */
    @GetMapping("/getQRCode")
    @ResponseBody
    public void getQRCode(HttpServletResponse response ) throws IOException {
        String qrCodeUrl = "需要生成的内容";
        qrCodeUrl="http://5kx9zh.natappfree.cc/api/alipay/chongzhi";
//        String qrCodeUrl = info;
        try {
            QrConfig qrConfig = new QrConfig(300, 300);
            QrCodeUtil.generate(qrCodeUrl, qrConfig, "png", response.getOutputStream());
//            log.info("生成二维码成功!");
            System.out.println("生成二维码成功!");
        } catch (QrCodeException | IOException e) {
//            log.error("发生错误！ {}！", e.getMessage());
            System.out.println(e.getMessage());
        }
    }

}
